package com.service.impl;

import com.bean.entity.PowerInfo;
import com.bean.pojo.PageAssistant;
import com.dao.PowerInfoMapper;
import com.service.PowerInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * User: 刘文雄
 * Date:2022/3/30 14:36
 * 权限表基础业务逻辑实现类
 */
@Service
public class PowerInfoServiceImpl implements PowerInfoService {
    @Autowired
    private PowerInfoMapper powerInfoMapper;
    @Override
    public int save(PowerInfo t) throws Exception {

        int insert = powerInfoMapper.insert(t);
        if (insert==1) return 1;
        throw new Exception("新增权限失败");
    }
    @Override
    public int remove(PowerInfo t) throws Exception {
        int delete = powerInfoMapper.delete(t);
        if (delete==1) return 1;
        throw new Exception("删除权限失败");
    }
    @Override
    public int modify(PowerInfo t) throws Exception {
        int update = powerInfoMapper.update(t);
        if (update==1) return 1;
        throw new Exception("修改权限失败");
    }
    @Override
    public PowerInfo unique(PowerInfo t) throws Exception {
        List<PowerInfo> powerInfoList = powerInfoMapper.select(t);
        if (powerInfoList.size() !=1)
            throw new Exception("没有此权限");
        return powerInfoList.get(0);
    }
    @Override
    public List<PowerInfo> query(PowerInfo t) {
        List<PowerInfo> powerInfoList = powerInfoMapper.select(t);
        return powerInfoList;
    }
    @Override
    public PageAssistant<PowerInfo> queryByPage(Map<String, Object> map, PageAssistant<PowerInfo> pa) {

        //查询并设置记录总数
        pa.setCount(powerInfoMapper.selectCount(map));
        //添加分页参数
        map.put("startCode", pa.getStartCode());
        map.put("pageSize", pa.getPageSize());
        //查询并设置页面内容
        pa.setItems(powerInfoMapper.selectByPage(map));
        return pa;
    }
}
